var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
      indicatorDots: false,
      autoplay: false,
      interval: 5000,
      duration: 1000,
      showVideo: [],
      showVideoView: [],
      tempIndex: 0 ,
    xiaochengxu:0,
     bannerList:[]
  },


  toAsk:function(){
    wx.navigateTo({
      url: 'page/ask/ask',
    })
  },
  toVideo: function () {
    wx.navigateTo({
      url: '../../pages/booklist/booklist',
    })
  },
  toBlessing: function () {
    if (app.globalData.myId == null || app.globalData.myId == undefined || app.globalData.myId == '') {
      wx.navigateTo({
        url: '../login/login',
      })
    } else {
      wx.navigateTo({
        url: 'page/blessing/blessing',
      })
    }
    
  },
  toMakeAnAppointment: function () {
    if (app.globalData.myId == null || app.globalData.myId == undefined || app.globalData.myId == '') {
      wx.navigateTo({
        url: '../login/login',
      })
    } else {
    wx.navigateTo({
      url: 'page/makeAnAppointment/makeAnAppointment',
    })
    }
  },
 
 
  tolearn: function () {
    wx.navigateTo({
      url: 'page/ask2/ask2',
    })
  },
  
  getList: function () {

    var that = this
    var bannerbox=[]
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/IndexApp/homepage',
      data: { 
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
    
     
          that.setData({
            banner: res.data.data.banner
          })    
        for (var i = 0; i < res.data.data.banner.length; i++) { 
          bannerbox.push(res.data.data.banner[i])         
          }           
      }
    })
  },
  bindPlay: function (e) {
    var index = e.currentTarget.dataset.index
    console.log(index)
    this.videoContext = wx.createVideoContext('video' + index)
    this.videoContext.play({
    })
    var tem1 = this.data.showVideo
    var tem2 = this.data.showVideoView
    tem1[index] = true
    tem2[index] = false
    this.setData({
      showVideo: tem1,
      showVideoView: tem2,
    })
  },
  moreVideo: function () {
    wx.navigateTo({
      url: 'page/moreVideo/moreVideo',
    })
  },
 
  gobannerUrl: function () {
    wx.navigateTo({
      url: 'page/bannerUrl/bannerUrl',
    })
  },
  getUnLoginData: function () {
    var that = this
    wx.showLoading({
      title: '加载中...',
    })
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/Index/index_nologin',
      data: {
  
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.hideLoading()
        if (res.data.status === 1) {
          that.setData({
            course: res.data.course,
            description: res.data.description
          })
          var tem1 = []
          var temp2 = []
          for (var i = 0; i < that.data.course.length; i++) {
            tem1.push(false)
            temp2.push(true)
          }
          that.setData({
            showVideo: tem1,
            showVideoView: temp2,
          })
        } else {

        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },

  getBanner:function(){
    var that = this

    wx.request({
      url: 'https://xiaochengxu.fincoder.com/index.php/Home/IndexApp/index',
      data: {

      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.hideLoading()
        if (res.data.status === 1) {
        that.setData({
          bannerList: res.data.data
        })
        } else {

        }
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },

  q: function () {
    wx.navigateBack({ changed: true })
  },
  qq: function () {
    wx.switchTab({

      url: '/pages/index/index',

    });
  },
  onReady: function () {
    const vm = this
    vm.setData({
      statusBarHeight: getApp().globalData.statusBarHeight,
      titleBarHeight: getApp().globalData.titleBarHeight
    })

  },

  onLoad: function (options) {
    var that=this
    that.getList()   
    that.getUnLoginData()
    that.getBanner()
    if (options.detailId != null && options.detailId != '' && options.detailId!=undefined ){
      wx.navigateTo({
        url: '../booklist/page/viewpoint/viewpoint?id=' + options.detailId,
      })
    
    } else if (options.detailId2 != null && options.detailId2 != '' && options.detailId2 != undefined){
      wx.navigateTo({
        url: '../booklist/page/DetailsOfQuestions/DetailsOfQuestions?id=' + options.detailId2,
      })
      
    }
    wx.request({
      url: 'https://xiaochengxu.fincoder.com/banben.php',

      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        wx.hideLoading()
          that.setData({
            xiaochengxu: res.data.xiaochengxu,

          })
          
      }, fail: function () {
        wx.hideLoading()
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },

  toweb:function(e){
    console.log(e)
    var index=e.currentTarget.dataset.index
    var that = this
    if (this.data.bannerList[index].jumpurl != '' && this.data.bannerList[index].jumpurl != undefined ){
        wx.navigateTo({
          url: 'page/bannerweb/bannerweb?url=' + that.data.bannerList[index].jumpurl
          
        })
    }
  },
  /**
 * 用户点击右上角分享
 */
  onShareAppMessage: function () {
    return {
      title: "A计划"
     
    }
  }

})